import {action, makeAutoObservable, observable} from "mobx";
import {GET_WEBSITE_MSG, SERVER_PICTURE_URL} from "../api/APIURLDefine";
import {AxioInstance} from "../api/AxiosHelper";


class GlobalStore {

    constructor() {
        makeAutoObservable(this)
        AxioInstance.get(`${GET_WEBSITE_MSG}`).then((resp: any) => {
            try {
                resp = JSON.parse(resp);
                this.website = resp;
                // console.log(resp);
                window.document.title = resp.siteName || "实验教学管理平台";
                (window.document.getElementById("icon") as any).href = SERVER_PICTURE_URL + resp.siteIcon || "%PUBLIC_URL%/icon.png";
            } catch (error) {

            }

        }).catch(e => console.error(e));

    }

    //登录弹窗
    @observable showLoginModal: boolean = false;

    @action updateShowLoginModalVisiable(value: boolean) {
        this.showLoginModal = value;
        // if (!value) {
        //     setTimeout(() => {
        //         window.location.reload();
        //     }, 200)
        // }
    }

    //主页搜索框
    @observable showSearch: boolean = true;

    @action SetShowSearch(value: boolean) {
        this.showSearch = value;
    }

    //身份认证弹窗
    @observable showAuthModal: boolean = false;

    @action updateShowAuthModalVisible(value: boolean) {
        this.showAuthModal = value;
    }

    @observable loginType: LoginType = LoginType.THINK;


    @action SetLoginType(value: LoginType) {
        this.loginType = value;
    }

    @observable DOMainName: string = "";

    @action SetDOMainName(value: string) {
        this.DOMainName = value;
    }

    @observable RegisterByEmail: boolean = true;

    @action SeRegisterByEmail(value: boolean) {
        this.RegisterByEmail = value;
    }

    @observable website: any = {};

}

export enum LoginType {
    THINK = 0,
    ILAB = 1
}

export default GlobalStore;